nginx: honour X-Force-Refresh header for per-request cache bypass#2
Merged
Conversation
The previous $force_refresh map keyed off $request_uri with a single
${FORCE_CACHE_REFRESH_ON_REQUEST} default -- meaning every URI mapped
to the same env-var value. No per-request control. Useful only as a
global toggle (currently false).
After v1.14.x VFBquery releases we need a way to overwrite
canonical cache slots for the (query_type, entity_id) matrix in the
background so end-users never pay the cold-miss latency. Combined
with proxy_cache_use_stale updating + proxy_cache_background_update
(already on), this gives stale-while-revalidate semantics plus an
explicit warmup hook.
Wire shape:
map $http_x_force_refresh $force_refresh {
default ${FORCE_CACHE_REFRESH_ON_REQUEST};
"~*^(true|1|yes)$" 1;
}
`proxy_cache_bypass $force_refresh;` is unchanged downstream and
critically `proxy_no_cache` is NOT set, so the upstream response from
a force-refreshed request overwrites the canonical cache entry --
subsequent normal users get the fresh body. Header-not-query-param is
deliberate: the cache key includes the URI so a `?force_refresh=true`
query param would land the fresh response in a different cache slot
than the slot normal users read from. Header has zero effect on the
key.
Companion: owlery-cache-reload --force-refresh (separate PR) sets
this header on every request during the post-release warmup pass.
Operational note: owl_cache should sit behind the VFB firewall and
v3-cached.virtualflybrain.org is only reachable from the internet via
the Informatics LBs. If external exposure for X-Force-Refresh ever
becomes a worry, gate the header inside the existing
$is_whitelisted_ip machinery in this file. Not done here -- the
overhead of an extra map for a clearly-internal-only tool is more
mechanism than the threat warrants today.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the NGINX cache-bypass mechanism to support a per-request cache refresh trigger via the X-Force-Refresh header, enabling controlled cache warmups that overwrite the canonical cache entry without changing the cache key.
Changes:
- Replace the
$force_refreshmap input from$request_urito$http_x_force_refreshto allow header-driven bypass. - Add detailed inline documentation explaining why the header approach preserves canonical cache slots while enabling explicit warmups.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous $force_refresh map keyed off$request_uri with a single $ {FORCE_CACHE_REFRESH_ON_REQUEST} default -- meaning every URI mapped to the same env-var value. No per-request control. Useful only as a global toggle (currently false).
After v1.14.x VFBquery releases we need a way to overwrite canonical cache slots for the (query_type, entity_id) matrix in the background so end-users never pay the cold-miss latency. Combined with proxy_cache_use_stale updating + proxy_cache_background_update (already on), this gives stale-while-revalidate semantics plus an explicit warmup hook.
Wire shape:
map $http_x_force_refresh $force_refresh {
default ${FORCE_CACHE_REFRESH_ON_REQUEST};
"~*^(true|1|yes)$" 1;
}
proxy_cache_bypass $force_refresh;is unchanged downstream and criticallyproxy_no_cacheis NOT set, so the upstream response from a force-refreshed request overwrites the canonical cache entry -- subsequent normal users get the fresh body. Header-not-query-param is deliberate: the cache key includes the URI so a?force_refresh=truequery param would land the fresh response in a different cache slot than the slot normal users read from. Header has zero effect on the key.Companion: owlery-cache-reload --force-refresh (separate PR) sets this header on every request during the post-release warmup pass.
Operational note: owl_cache should sit behind the VFB firewall and v3-cached.virtualflybrain.org is only reachable from the internet via the Informatics LBs. If external exposure for X-Force-Refresh ever becomes a worry, gate the header inside the existing $is_whitelisted_ip machinery in this file. Not done here -- the overhead of an extra map for a clearly-internal-only tool is more mechanism than the threat warrants today.